package com.atguigu.gulimall.shares;

import com.alibaba.cloud.nacos.NacosConfigAutoConfiguration;
import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration;
import com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration;
import com.alibaba.nacos.api.config.annotation.NacosConfigurationProperties;
import com.atguigu.common.utils.R;
import com.atguigu.gulimall.shares.dto.SharesDto;
import com.atguigu.gulimall.shares.service.SharesService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@SpringBootApplication(exclude = {NacosConfigAutoConfiguration.class, DataSourceAutoConfiguration.class})
public class GulimallSharesApplication {

    public static void main(String[] args) throws InterruptedException {
        String queryItem = "sh603982,sh600316,sz002531,sz002241,sz002026,sz002242,sh000001,sz399006"; 
        ConfigurableApplicationContext run = SpringApplication.run(GulimallSharesApplication.class, args);
        SharesService sharesService = run.getBean("sharesService", SharesService.class);
        List<String> outMsg = new ArrayList<>();
        while (true){
            R result = sharesService.getByCode(queryItem);
            List<SharesDto> sharesDtos  = (List<SharesDto>)result.get("data");
            for (SharesDto item : sharesDtos) {
                String sharesName = item.getSharesName().split("=")[1];
                outMsg.add(sharesName.substring(1)+"\t\t\t"+item.getCurrentPrice()+"\t\t\t"+item.getFluctuationRange());
            }
            System.out.println("  名称\t\t\t\t当前价格\t\t涨跌幅");
            outMsg.forEach(item->{
                System.out.println(item);
            });
            outMsg = new ArrayList<>();
            System.out.println("\n\n\n\n");

            Thread.sleep(3000);
        }
    }

}
